package com.ctshk.rpc.order.custom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderTouristPrice;
import com.ctshk.rpc.order.custom.mapper.CustomizedOrderTouristPriceMapper;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderTouristPriceService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 定制包团订单游客自由报价 服务实现类
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
@DubboService
public class CustomizedOrderTouristPriceServiceImpl extends ServiceImpl<CustomizedOrderTouristPriceMapper, CustomizedOrderTouristPrice> implements ICustomizedOrderTouristPriceService {

    @Autowired
    private CustomizedOrderTouristPriceMapper orderTouristPriceMapper;


    /**
     * 清空订单报价
     *
     * @param orderId
     * @param userId
     * @return
     */
    @Override
    public boolean cleanByOrder(Long orderId, Long userId) {
        QueryWrapper<CustomizedOrderTouristPrice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_id",orderId);
        queryWrapper.eq("is_deleted",0);
        List<CustomizedOrderTouristPrice> list = orderTouristPriceMapper.selectList(queryWrapper);
        if (list != null && list.size() > 0){
            list.forEach(touristPrice -> {
                touristPrice.setModifiedId(userId);
                touristPrice.setIsDeleted(1);
            });
           return updateBatchById(list);
        }
        return true;
    }
}
